<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - include/caffe/util/mkl_alternate.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">include/caffe/util</a> - mkl_alternate.hpp<span style="font-size: 80%;"> (source / <a href="mkl_alternate.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">14</td>
            <td class="headerCovTableEntryLo">28.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">20</td>
            <td class="headerCovTableEntryLo">10.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef CAFFE_UTIL_MKL_ALTERNATE_H_</a>
<span class="lineNum">       2 </span>            : #define CAFFE_UTIL_MKL_ALTERNATE_H_
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #ifdef USE_MKL
<span class="lineNum">       5 </span>            : 
<span class="lineNum">       6 </span>            : #include &lt;mkl.h&gt;
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : #else  // If use MKL, simply include the MKL header
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #ifdef USE_ACCELERATE
<span class="lineNum">      11 </span>            : #include &lt;Accelerate/Accelerate.h&gt;
<span class="lineNum">      12 </span>            : #else
<span class="lineNum">      13 </span>            : extern &quot;C&quot; {
<span class="lineNum">      14 </span>            : #include &lt;cblas.h&gt;
<span class="lineNum">      15 </span>            : }
<span class="lineNum">      16 </span>            : #endif  // USE_ACCELERATE
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &lt;math.h&gt;
<span class="lineNum">      19 </span>            : 
<span class="lineNum">      20 </span>            : // Functions that caffe uses but are not present if MKL is not linked.
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : // A simple way to define the vsl unary functions. The operation should
<span class="lineNum">      23 </span>            : // be in the form e.g. y[i] = sqrt(a[i])
<span class="lineNum">      24 </span>            : #define DEFINE_VSL_UNARY_FUNC(name, operation) \
<span class="lineNum">      25 </span>            :   template&lt;typename Dtype&gt; \
<span class="lineNum">      26 </span>            :   void v##name(const int n, const Dtype* a, Dtype* y) { \
<span class="lineNum">      27 </span>            :     CHECK_GT(n, 0); CHECK(a); CHECK(y); \
<span class="lineNum">      28 </span>            :     for (int i = 0; i &lt; n; ++i) { operation; } \
<span class="lineNum">      29 </span>            :   } \
<span class="lineNum">      30 </span>            :   inline void vs##name( \
<span class="lineNum">      31 </span>            :     const int n, const float* a, float* y) { \
<span class="lineNum">      32 </span>            :     v##name&lt;float&gt;(n, a, y); \
<span class="lineNum">      33 </span>            :   } \
<span class="lineNum">      34 </span>            :   inline void vd##name( \
<span class="lineNum">      35 </span>            :       const int n, const double* a, double* y) { \
<span class="lineNum">      36 </span>            :     v##name&lt;double&gt;(n, a, y); \
<a name="37"><span class="lineNum">      37 </span>            :   }</a>
<a name="38"><span class="lineNum">      38 </span>            : </a>
<a name="39"><span class="lineNum">      39 </span><span class="lineNoCov">          0 : DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i])</span></a>
<a name="40"><span class="lineNum">      40 </span><span class="lineNoCov">          0 : DEFINE_VSL_UNARY_FUNC(Sqrt, y[i] = sqrt(a[i]))</span></a>
<a name="41"><span class="lineNum">      41 </span><span class="lineCov">    4250320 : DEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i]))</span></a>
<span class="lineNum">      42 </span><span class="lineNoCov">          0 : DEFINE_VSL_UNARY_FUNC(Ln, y[i] = log(a[i]))</span>
<span class="lineNum">      43 </span><span class="lineNoCov">          0 : DEFINE_VSL_UNARY_FUNC(Abs, y[i] = fabs(a[i]))</span>
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            : // A simple way to define the vsl unary functions with singular parameter b.
<span class="lineNum">      46 </span>            : // The operation should be in the form e.g. y[i] = pow(a[i], b)
<span class="lineNum">      47 </span>            : #define DEFINE_VSL_UNARY_FUNC_WITH_PARAM(name, operation) \
<span class="lineNum">      48 </span>            :   template&lt;typename Dtype&gt; \
<span class="lineNum">      49 </span>            :   void v##name(const int n, const Dtype* a, const Dtype b, Dtype* y) { \
<span class="lineNum">      50 </span>            :     CHECK_GT(n, 0); CHECK(a); CHECK(y); \
<span class="lineNum">      51 </span>            :     for (int i = 0; i &lt; n; ++i) { operation; } \
<span class="lineNum">      52 </span>            :   } \
<span class="lineNum">      53 </span>            :   inline void vs##name( \
<span class="lineNum">      54 </span>            :     const int n, const float* a, const float b, float* y) { \
<span class="lineNum">      55 </span>            :     v##name&lt;float&gt;(n, a, b, y); \
<span class="lineNum">      56 </span>            :   } \
<span class="lineNum">      57 </span>            :   inline void vd##name( \
<span class="lineNum">      58 </span>            :       const int n, const double* a, const float b, double* y) { \
<span class="lineNum">      59 </span>            :     v##name&lt;double&gt;(n, a, b, y); \
<a name="60"><span class="lineNum">      60 </span>            :   }</a>
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span><span class="lineNoCov">          0 : DEFINE_VSL_UNARY_FUNC_WITH_PARAM(Powx, y[i] = pow(a[i], b))</span>
<span class="lineNum">      63 </span>            : 
<span class="lineNum">      64 </span>            : // A simple way to define the vsl binary functions. The operation should
<span class="lineNum">      65 </span>            : // be in the form e.g. y[i] = a[i] + b[i]
<span class="lineNum">      66 </span>            : #define DEFINE_VSL_BINARY_FUNC(name, operation) \
<span class="lineNum">      67 </span>            :   template&lt;typename Dtype&gt; \
<span class="lineNum">      68 </span>            :   void v##name(const int n, const Dtype* a, const Dtype* b, Dtype* y) { \
<span class="lineNum">      69 </span>            :     CHECK_GT(n, 0); CHECK(a); CHECK(b); CHECK(y); \
<span class="lineNum">      70 </span>            :     for (int i = 0; i &lt; n; ++i) { operation; } \
<span class="lineNum">      71 </span>            :   } \
<span class="lineNum">      72 </span>            :   inline void vs##name( \
<span class="lineNum">      73 </span>            :     const int n, const float* a, const float* b, float* y) { \
<span class="lineNum">      74 </span>            :     v##name&lt;float&gt;(n, a, b, y); \
<span class="lineNum">      75 </span>            :   } \
<span class="lineNum">      76 </span>            :   inline void vd##name( \
<span class="lineNum">      77 </span>            :       const int n, const double* a, const double* b, double* y) { \
<span class="lineNum">      78 </span>            :     v##name&lt;double&gt;(n, a, b, y); \
<a name="79"><span class="lineNum">      79 </span>            :   }</a>
<a name="80"><span class="lineNum">      80 </span>            : </a>
<a name="81"><span class="lineNum">      81 </span><span class="lineNoCov">          0 : DEFINE_VSL_BINARY_FUNC(Add, y[i] = a[i] + b[i])</span></a>
<a name="82"><span class="lineNum">      82 </span><span class="lineNoCov">          0 : DEFINE_VSL_BINARY_FUNC(Sub, y[i] = a[i] - b[i])</span></a>
<span class="lineNum">      83 </span><span class="lineNoCov">          0 : DEFINE_VSL_BINARY_FUNC(Mul, y[i] = a[i] * b[i])</span>
<span class="lineNum">      84 </span><span class="lineCov">   51003840 : DEFINE_VSL_BINARY_FUNC(Div, y[i] = a[i] / b[i])</span>
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            : // In addition, MKL comes with an additional function axpby that is not present
<span class="lineNum">      87 </span>            : // in standard blas. We will simply use a two-step (inefficient, of course) way
<span class="lineNum">      88 </span>            : // to mimic that.
<span class="lineNum">      89 </span>            : inline void cblas_saxpby(const int N, const float alpha, const float* X,
<span class="lineNum">      90 </span>            :                          const int incX, const float beta, float* Y,
<span class="lineNum">      91 </span>            :                          const int incY) {
<span class="lineNum">      92 </span><span class="lineCov">      80000 :   cblas_sscal(N, beta, Y, incY);</span>
<span class="lineNum">      93 </span><span class="lineCov">      80000 :   cblas_saxpy(N, alpha, X, incX, Y, incY);</span>
<span class="lineNum">      94 </span>            : }
<span class="lineNum">      95 </span>            : inline void cblas_daxpby(const int N, const double alpha, const double* X,
<span class="lineNum">      96 </span>            :                          const int incX, const double beta, double* Y,
<span class="lineNum">      97 </span>            :                          const int incY) {
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :   cblas_dscal(N, beta, Y, incY);</span>
<span class="lineNum">      99 </span><span class="lineNoCov">          0 :   cblas_daxpy(N, alpha, X, incX, Y, incY);</span>
<span class="lineNum">     100 </span>            : }
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span>            : #endif  // USE_MKL
<span class="lineNum">     103 </span>            : #endif  // CAFFE_UTIL_MKL_ALTERNATE_H_
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
